package com.gilly;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/LoginService")
public class LoginServiceServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String id = (String)request.getAttribute("id");
		String password = (String)request.getAttribute("password");
		PrintWriter out = response.getWriter();
		
		MemberDAO dao = new MemberDAO();
		ArrayList<MemberDTO> list = dao.login(id);
		if(list.size() == 0){
			out.print("아이디와 비밀번호를 확인해주세요");
		}else{
		out.print(list.get(0).getId());
		out.print(list.get(0).getPassword());
		response.sendRedirect("main.html");
		}
	}
}
